package org.dromara.oce.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.oce.domain.bo.OceTitleBo;
import org.dromara.oce.domain.qo.OceTitleQo;
import org.dromara.oce.domain.vo.OceTitleVo;
import org.dromara.oce.service.OceTitleService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 巨量广告标题、产品卖点、行动号召
 *
 * @author dsbb
 * @date 2025-06-11
 * @module 管理平台接口
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/oce/title")
@SaIgnore
public class OceTitleController extends BaseController {

    private final OceTitleService oceTitleService;

    /**
     * 查询巨量广告标题、产品卖点、行动号召列表
     */
    @SaCheckPermission("oce:title:list")
    @GetMapping("/list")
    public TableDataInfo<OceTitleVo> list(OceTitleQo qo, PageQuery pageQuery) {
        return oceTitleService.queryPageList(qo, pageQuery);
    }

//    /**
//     * 导出巨量广告标题、产品卖点、行动号召列表
//     */
//    @SaCheckPermission("oce:title:export")
//    @Log(title = "巨量广告标题、产品卖点、行动号召", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(OceTitleQo qo, HttpServletResponse response) {
//        List<OceTitleVo> list = oceTitleService.queryList(qo);
//        ExcelUtil.exportExcel(list, "巨量广告标题、产品卖点、行动号召", OceTitleVo.class, response);
//    }

    /**
     * 获取巨量广告标题、产品卖点、行动号召详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("oce:title:query")
    @GetMapping("/{id}")
    public R<OceTitleVo> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long id) {
        return R.ok(oceTitleService.queryById(id));
    }

    /**
     * 新增巨量广告标题、产品卖点、行动号召
     */
//    @SaCheckPermission("oce:title:add")
    @Log(title = "巨量广告标题、产品卖点、行动号召", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody OceTitleBo bo) {
        return toAjax(oceTitleService.insertByBo(bo));
    }

    /**
     * 修改巨量广告标题、产品卖点、行动号召
     */
    @SaCheckPermission("oce:title:edit")
    @Log(title = "巨量广告标题、产品卖点、行动号召", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody OceTitleBo bo) {
        return toAjax(oceTitleService.updateByBo(bo));
    }

    /**
     * 删除巨量广告标题、产品卖点、行动号召
     *
     * @param ids 主键串
     */
    @SaCheckPermission("oce:title:remove")
    @Log(title = "巨量广告标题、产品卖点、行动号召", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(oceTitleService.deleteWithValidByIds(List.of(ids), true));
    }
}
